<template>
	<view>
		<!-- 浏览记录页面 -->
		<scroll-view scroll-y="true" style="height: 100vh;" refresher-background="#f5f5f5" @scrolltolower="loadMore">

			<u-swipe-action>
				<view class="historyDiv" v-for="(item,index) in dataList" :key="index">
					<u-swipe-action-item :options="options1" @click="delClick(item)">
						<view style="display: flex;gap: 20rpx;padding: 20rpx;border-radius: 20rpx;">
							<view class="historyDiv-item">
								<img :src="item.photo" alt="" />
							</view>
							<view style="width: 400rpx;">
								<view v-if="item.type==0" style="white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;width: 100%;">{{item.title}}</view>
								<view v-if="item.type==1" style="white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;width: 100%;">{{item.name}}</view>
								<view style="margin-top: 20rpx;">
									<view v-if="item.type==0" style="display: flex;align-items: center;gap: 20rpx;">
										<img style="width: 50rpx;height: 50rpx;" v-if="item.authorPhoto !=''"
											:src="item.authorPhoto" alt="" />
										<img style="width: 50rpx;height: 50rpx;" v-else
											src="../../static/missing-face.png" alt="" />
										<span>{{item.author}}</span>
									</view>
									<view v-if="item.type==1" style="color: orange;">￥{{item.sellingPrice}}</view>
								</view>
								<view style="font-size: 20rpx;margin-top: 20rpx;">
									{{item.createTime}}
								</view>
							</view>

						</view>
					</u-swipe-action-item>
				</view>
			</u-swipe-action>
		</scroll-view>
	</view>
</template>

<script>
	import {
		browsingHistoryList,
		browsingHistoryDelete
	} from '@/api/userCenter.js'
	export default {
		data() {
			return {
				options1: [{
					text: '删除'
				}],
				page: {
					pageNum: 1,
					pageSize: 10
				},
				dataList: []
			};
		},
		methods: {
			loadMore() {
				this.page.pageSize = this.page.pageSize + 5
				this.getList()
			},
			async getList() {
				let res = await browsingHistoryList(this.page)
				if (res.code == 200) {
					this.dataList = res.data.list
				}
			},
			// 删除
			async delClick(item) {
				let res = await browsingHistoryDelete({
					id: item.id
				})
				console.log(res, 123);
				if (res.code == 200) {
					console.log(res, 222);
					this.getList()
				}
			}
		},
		onLoad() {
			this.getList()
		}
	}
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}

	.historyDiv {
		width: 100%;
		padding: 20rpx 20rpx 0 20rpx;
		border-radius: 20rpx;

		::v-deep .u-swipe-action-item__right__button__wrapper {
			background-color: red !important;
		}

		.historyDiv-item {

			img {
				width: 250rpx;
				height: 140rpx;
				border-radius: 20rpx;
			}
		}
	}
</style>